package cn.itcast.service.company.impl;

import cn.itcast.service.company.CompanyService;
import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.company.Company;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vo.PageResult;

import java.util.List;
import java.util.UUID;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyDao companyDao;

    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }

    @Override
    public void save(Company company) {
        company.setId(UUID.randomUUID().toString());
        companyDao.save(company);
    }

    @Override
    public Company findById(String id) {
        return companyDao.findById(id);
    }

    @Override
    public void update(Company company) {
        companyDao.update(company);
    }

    @Override
    public void delete(String id) {
        companyDao.delete(id);
    }

    @Override
    public PageResult findPage(int page, int size) {
        long total = companyDao.findCount();
        List list = companyDao.findPage((page - 1) * size, size);
        return new PageResult(total, list, page, size);
    }

    @Override
    public PageInfo findPageByHelper(int page, int size) {
        PageHelper.startPage(page,size);
        List<Company> list = companyDao.findAll();
        return new PageInfo(list);
    }


}
